package com.sangsang.ck.injector;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.sangsang.ck.methods.BatchInsert;
import com.sangsang.ck.methods.CkBatchDeleteByIds;
import com.sangsang.ck.methods.CkQueryMutationsCount;
import com.sangsang.ck.methods.SelectExistIdByIds;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author liutangqi
 * @date 2023/12/20 22:16
 */
@Component
@ConditionalOnProperty(name = "spring.datasource.driver-class-name", havingValue = "com.clickhouse.jdbc.ClickHouseDriver")
public class CustomSqlInjector extends DefaultSqlInjector {

    @Value("${spring.datasource.url}")
    private String url;

    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
        List<AbstractMethod> methodList = super.getMethodList(mapperClass);
        methodList.add(new BatchInsert());
        methodList.add(new SelectExistIdByIds());
        methodList.add(new CkBatchDeleteByIds());
        methodList.add(new CkQueryMutationsCount(url));
        return methodList;
    }
}
